{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ba986c8a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "============================================================\n",
      "🩺 Processing Record 100\n",
      "============================================================\n",
      "✅ Number of heartbeats extracted: 2271\n",
      "\n",
      "=== Combined ECG Prediction Summary ===\n",
      "\n",
      "🧠 Beat morphology analysis:\n",
      "- Classified as 'Normal' with 69.5% confidence.\n",
      "\n",
      "🫀 Heart disease screening:\n",
      "- Indicates 'Abnormal' condition with 97.0% confidence.\n",
      "\n",
      "📋 Interpretation:\n",
      "- Note: Beat morphology refers to the shape of ECG signals.\n",
      "- Disease status is based on broader patterns beyond individual beats.\n",
      "- A normal beat does not rule out underlying heart conditions.\n",
      "- Clinical review is recommended for further evaluation.\n",
      "\n",
      "✅ Number of heartbeats analyzed: 2271\n",
      "\n",
      "============================================================\n",
      "🩺 Processing Record 101\n",
      "============================================================\n",
      "✅ Number of heartbeats extracted: 1865\n",
      "\n",
      "=== Combined ECG Prediction Summary ===\n",
      "\n",
      "🧠 Beat morphology analysis:\n",
      "- Classified as 'Normal' with 36.1% confidence.\n",
      "\n",
      "🫀 Heart disease screening:\n",
      "- Indicates 'Abnormal' condition with 78.0% confidence.\n",
      "\n",
      "📋 Interpretation:\n",
      "- Note: Beat morphology refers to the shape of ECG signals.\n",
      "- Disease status is based on broader patterns beyond individual beats.\n",
      "- A normal beat does not rule out underlying heart conditions.\n",
      "- Clinical review is recommended for further evaluation.\n",
      "\n",
      "✅ Number of heartbeats analyzed: 1865\n",
      "\n",
      "============================================================\n",
      "🩺 Processing Record 102\n",
      "============================================================\n",
      "✅ Number of heartbeats extracted: 2186\n",
      "\n",
      "=== Combined ECG Prediction Summary ===\n",
      "\n",
      "🧠 Beat morphology analysis:\n",
      "- Classified as 'Unknown' with 58.2% confidence.\n",
      "\n",
      "🫀 Heart disease screening:\n",
      "- Indicates 'Abnormal' condition with 83.5% confidence.\n",
      "\n",
      "📋 Interpretation:\n",
      "- Note: Beat morphology refers to the shape of ECG signals.\n",
      "- Disease status is based on broader patterns beyond individual beats.\n",
      "- A normal beat does not rule out underlying heart conditions.\n",
      "- Clinical review is recommended for further evaluation.\n",
      "\n",
      "✅ Number of heartbeats analyzed: 2186\n",
      "\n",
      "============================================================\n",
      "🩺 Processing Record 103\n",
      "============================================================\n",
      "✅ Number of heartbeats extracted: 2084\n",
      "\n",
      "=== Combined ECG Prediction Summary ===\n",
      "\n",
      "🧠 Beat morphology analysis:\n",
      "- Classified as 'Normal' with 49.0% confidence.\n",
      "\n",
      "🫀 Heart disease screening:\n",
      "- Indicates 'Abnormal' condition with 82.9% confidence.\n",
      "\n",
      "📋 Interpretation:\n",
      "- Note: Beat morphology refers to the shape of ECG signals.\n",
      "- Disease status is based on broader patterns beyond individual beats.\n",
      "- A normal beat does not rule out underlying heart conditions.\n",
      "- Clinical review is recommended for further evaluation.\n",
      "\n",
      "✅ Number of heartbeats analyzed: 2084\n",
      "\n",
      "============================================================\n",
      "🩺 Processing Record 104\n",
      "============================================================\n",
      "✅ Number of heartbeats extracted: 2224\n",
      "\n",
      "=== Combined ECG Prediction Summary ===\n",
      "\n",
      "🧠 Beat morphology analysis:\n",
      "- Classified as 'Unknown' with 59.9% confidence.\n",
      "\n",
      "🫀 Heart disease screening:\n",
      "- Indicates 'Abnormal' condition with 87.5% confidence.\n",
      "\n",
      "📋 Interpretation:\n",
      "- Note: Beat morphology refers to the shape of ECG signals.\n",
      "- Disease status is based on broader patterns beyond individual beats.\n",
      "- A normal beat does not rule out underlying heart conditions.\n",
      "- Clinical review is recommended for further evaluation.\n",
      "\n",
      "✅ Number of heartbeats analyzed: 2224\n"
     ]
    }
   ],
   "source": [
    "import wfdb\n",
    "import numpy as np\n",
    "import sys\n",
    "from model_predictor import ecg_predictor_both_models\n",
    "\n",
    "# === List of records you want to batch test ===\n",
    "record_ids = ['100', '101', '102', '103', '104']\n",
    "\n",
    "# === Batch processing ===\n",
    "for rec_id in record_ids:\n",
    "    print(\"\\n\" + \"=\"*60)\n",
    "    print(f\"🩺 Processing Record {rec_id}\")\n",
    "    print(\"=\"*60)\n",
    "\n",
    "    # Load recording\n",
    "    record = wfdb.rdrecord(rec_id, pn_dir='mitdb')\n",
    "    signal = record.p_signal[:, 0]  # Lead II\n",
    "    fs = record.fs\n",
    "\n",
    "    # Predict and generate report + get beat count\n",
    "    num_beats = ecg_predictor_both_models(signal, original_fs=fs)\n",
    "\n",
    "    print(f\"✅ Number of heartbeats analyzed: {num_beats}\")\n",
    "    sys.stdout.flush()\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "tf-gpu",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
